<template>
  <div class="app-container">
    <basic-container v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          size="mini"
          label-width="128px"
        >
          <el-form-item label="货物运输批次号" prop="manifestId">
            <el-input
              v-model.trim="queryParams.manifestId"
              placeholder="请输入货物运输批次号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="进出境标志" prop="iEFlag">
            <el-select v-model="queryParams.iEFlag" placeholder="请选择进出境类型" filterable>
              <el-option v-for="(item, index) in dict.type.mft_ieport_type" :key="index"
                         :label="item.value+'-' + item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="进出境海关代码" prop="customsCode">
            <el-select v-model="queryParams.customsCode" placeholder="请选择进出境海关代码" filterable>
              <el-option v-for="(item, index) in customsList" :key="index"
                         :label="item.customsCode + '-' + item.customsName" :value="item.customsCode"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </common-search>
    </basic-container>

    <basic-container>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddEdit('add')"
            v-hasPermi="['swdecl:mftTalHead:add']"
          >新增
          </el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-upload"
            size="mini"
            @click="handleDecl"
            v-hasPermi="['swdecl:mftTalHead:decl']"
          >申报
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            @click="handleDeclDelete"
            v-hasPermi="['swdecl:mftTalHead:decl']"
          >撤销
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['swdecl:mftTalHead:remove']"
          >删除
          </el-button
          >
        </el-col>
        <el-col :span="1.5" v-hasPermi="['swdecl:mftTalHead:list']">
          <!-- 查看回执 -->
          <view-response :disabled="single" :msgType="mType" :checkedId="manifestIdList"></view-response>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['bt:mftTalHead:export']"
          >导出</el-button>
        </el-col>
        -->
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <!-- 列表 -->
      <basic-table
        ref="tableList"
        :columns="columns"
        :tableData="tableData"
        :total="pageParams.total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
        :loading="loading"
        :needCheckbox="true"
        @selectionChange="handleSelectionChange"
      >
        <template #transportMode="scope">
          <dict-value :list="dict.type.bt_transport_mode" :dictCode="scope.row.transportMode"></dict-value>
        </template>
        <template #iEFlag="scope">
          <dict-tag :options="dict.type.sys_i_e_flag" :value="scope.row.iEFlag"></dict-tag>
        </template>
        <template #ieCustomsCode="scope">
          {{ scope.row.ieCustomsCode }}-
          <dict-value :list="customsList" :dictCode="scope.row.ieCustomsCode" label="customsName"
                      value="customsCode"></dict-value>
        </template>
        <template #customMasterCode="scope">
          {{ scope.row.ieCustomsCode }}-
          <dict-value :list="customsList" :dictCode="scope.row.customMasterCode" label="customsName"
                      value="customsCode"></dict-value>
        </template>
        <template #declStatus="scope">
          <dict-tag :options="dict.type.mft_tal_decl_status" :value="scope.row.declStatus"></dict-tag>
        </template>
        <template #receiptStatus="scope">
          <dict-tag :options="dict.type.mft_response_code" :value="scope.row.receiptStatus"></dict-tag>
        </template>
        <template #operate="scope">
          <div class="option-menu">
            <!-- <el-button
              type="text"
              size="mini"
              class="table-edit"
              @click="handleAddEdit('edit', scope.row)"
              v-hasPermi="['bt:mftTalHead:edit']"
            >
              编辑
            </el-button> -->
            <el-button
              type="text"
              size="mini"
              class="table-edit"
              @click="handleDelete(scope.row)"
              v-hasPermi="['swdecl:mftTalHead:remove']"
            >
              删除
            </el-button>
            <el-button
              type="text"
              size="mini"
              class="table-edit"
              @click="handleDetail(scope.row)"
            >
              详情
            </el-button>
          </div>
        </template>
      </basic-table>
    </basic-container>

    <!-- 新增、编辑 -->
    <add-edit
      ref="addEdit"
      :dialogType="dialogType"
      :customsList="customsList"
      :rowData="rowData"
      :dict="dictProp"
      @handleQuery="handleQuery"
    />

    <!-- 详情 -->
    <detail-dialog ref="detail" :dict="dictProp" :detailId="detailId" :customsList="customsList"></detail-dialog>
  </div>
</template>

<script>
import {
  listMftTalRoadList,
  delMftTalRoadList,
  exportMftTalRoadList,
  declMftTalRoadList,
  delDeclMftTalRoadList
} from "@/api/swdecl/mftTalHead";
import addEdit from "./components/addEdit";
import detailDialog from "./components/detailDialog";
   import {findListCustoms} from "@/api/system/customs";
import ViewResponse from '../components/viewResponse.vue';

export default {
  name: "MftTalRoadList",
  dicts: ["sys_i_e_flag", "bt_transport_mode", "custom_wrap_type", "mft_communi_type", "mft_tal_decl_status", 'mft_response_code'],
  components: {
    addEdit,
    detailDialog,
    ViewResponse
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //数据查询条件
      mType: 'MT_54',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        manifestId: null,
        transportMode: null,
        iEFlag: null,
        declTrafMode: null,
        customsCode: null,
        msgId: null,
        billNo: null,
        talPartyId: null,
        talMasterName: null,
        talMasterPhone: null,
        talMasterFax: null,
        talMasterEmail: null,
        loadCode: null,
        unloadCode: null,
        talBeginDate: null,
        talEndDate: null,
        volume: null,
        volumeUnit: null,
        packNo: null,
        wrapType: null,
        grossWt: null,
        weightUnit: null,
        talMark: null,
        senderCode: null,
        sendMsgDate: null,
        receiverCode: null,
        recvMsgDate: null,
        auditEr: null,
        auditDate: null,
      },
      // 遮罩层
      loading: true,
      // 列表数据
      tableData: [],
      columns: [
        {
          prop: "manifestId",
          label: "运输批次号",
          align: "center",
          minWidth: 160
        },
        {
          prop: "iEFlag",
          label: "进出境标志",
          align: "center",
          minWidth: 100,
          slot: true
        },
        {
          prop: "ieCustomsCode",
          label: "进出境海关",
          align: "center",
          minWidth: 140,
          slot: true
        },
        {
          prop: "declStatus",
          label: "申报状态",
          align: "center",
          slot: true,
          minWidth: 120
        },
        {
          prop: "receiptStatus",
          label: "回执状态",
          align: "center",
          slot: true,
          minWidth: 120
        },
        {
          prop: "receiptRemark",
          label: "回执说明",
          align: "center",
          minWidth: 120
        },
        {
          prop: "unloadCode",
          label: "卸货地代码",
          align: "center",
          minWidth: 100
        },
        {
          prop: "loadCode",
          label: "装货地代码",
          align: "center",
          minWidth: 100
        },
        {
          prop: "startTalTime",
          label: "开始理货时间",
          align: "center",
          width: 140
        },
        {
          prop: "endTalTime",
          label: "结束理货时间",
          align: "center",
          width: 140
        }, {
          prop: "entCode",
          label: "企业代码",
          align: "center",
          minWidth: 120
        },

        {
          prop: "talCompanyCode",
          label: "理货公司代码",
          align: "center",
          minWidth: 140
        },
        {
          prop: "talMasterName",
          label: "理货责任人名称",
          align: "center",
          minWidth: 120
        },
        {
          prop: "customMasterCode",
          label: "传输企业备案关区	",
          align: "center",
          minWidth: 140,
          slot: true
        },
        // {
        //   prop: "declRemark",
        //   label: "申报说明",
        //   align: "center"
        // },
        // {
        //   prop: "receiptStatus",
        //   label: "回执状态",
        //   align: "center",
        //   slot: true
        // },
        // {
        //   prop: "receiptRemark",
        //   label: "回执说明",
        //   align: "center"
        // },
        // {
        //   prop: "remark",
        //   label: "备注",
        //   align: "center"
        // },
        {
          prop: "createBy",
          label: "创建人",
          align: "center"
        },
        {
          prop: "createTime",
          label: "创建时间",
          align: "center",
          width: 140
        },
        {
          prop: "operate",
          label: "操作",
          slot: true,
          width: 140,
          fixed: "right",
        },
      ],
      pageParams: {
        total: 0,
      },
      rowData: {},
      detailId: "",
      dialogType: "",
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 选中的批次号
      manifestIdList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //详情显示的时候，表单编辑禁用
      isViewDisabled: false,

      // 公路理货报告提运单表格数据
      mftTalRoadListList: [],

      //海关关区信息列表
      customsList: [],
    };
  },
  computed: {
    dictProp() {
      //字典list，为避免子组件重复调接口获取，用computed计算传值
      return {
        type: this.dict.type,
      };
    },
  },
  created() {
    this.getList();
    this.loadCustomsList();
  },
  methods: {
    /* 加载关区信息列表*/
    loadCustomsList() {
      findListCustoms().then(response => {
        this.customsList = response.data;
      });
    },
    /** 查询公路理货报告提运单列表 */
    getList() {
      this.loading = true;
      listMftTalRoadList(this.queryParams).then((response) => {
        this.tableData = response.rows;
        this.pageParams.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.$refs.tableList.toPageFirst();
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val.pageSize;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val.currentPage;
      this.getList();
    },
    // 新增/编辑
    handleAddEdit(type, row) {
      this.dialogType = type;
      if (row) {
        this.rowData = JSON.parse(JSON.stringify(row));
      }
      this.$refs.addEdit.open();
    },
    // 详情
    handleDetail(row) {
      this.detailId = row.id;
      this.$nextTick(() => {
        this.$refs.detail.open();
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      debugger;
      this.ids = selection.map((item) => item.id);
      this.manifestIdList = selection.map((item) => item.manifestId);
      console.log( this.manifestIdList);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除公路理货报告提运单编号为"' + ids + '"的数据项？')
        .then(function () {
          return delMftTalRoadList(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有公路理货报告提运单数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportMftTalRoadList(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {
        });
    },
    //申报
    handleDecl(row) {
      const billCodes = row.id || this.ids;
      if (billCodes == undefined || billCodes == null || billCodes == "") {
        this.$modal.alertError("请先选择要申报的单证数据！");
        return false;
      }
      this.$modal.confirm('是否确认申报业务编号为"' + billCodes + '"的数据项？').then(function () {
        return declMftTalRoadList(billCodes);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("申报提交成功");
      }).catch(() => {
      });
    },
    //删除申报
    handleDeclDelete(row) {
      const billCodes = row.id || this.ids;
      if (billCodes == undefined || billCodes == null || billCodes == "") {
        this.$modal.alertError("请先选择要删除申报的单证数据！");
        return false;
      }
      this.$modal.confirm('是否确认删除申报业务编号为"' + billCodes + '"的数据项？').then(function () {
        return delDeclMftTalRoadList(billCodes);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除申报提交成功");
      }).catch(() => {
      });
    },

  },
};
</script>


<style type="text/css">
.el-form-item .el-select {
  width: 100%;
}
</style>
